package com.ruoyi.marketing.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.service.ISysUserService;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.marketing.mapper.AwardPersonMapper;
import com.ruoyi.marketing.domain.AwardPerson;
import com.ruoyi.marketing.service.IAwardPersonService;

import java.util.List;

/**
 * 查看参加活动人数Service业务层处理
 *
 * @author hao
 * @date 2023-01-31
 */
@Service
public class AwardPersonServiceImpl extends ServiceImpl<AwardPersonMapper, AwardPerson> implements IAwardPersonService {
    @Autowired
    private ISysUserService sysUserService;

    @Override
    public List<AwardPerson> selectAwardPersonList() {
        List<AwardPerson> list = list();
        for (AwardPerson awardPerson : list) {
            SysUser byAllId = sysUserService.getByAllId(awardPerson.getUserId());
            if (byAllId != null) {
                awardPerson.setUser(byAllId);
            }
        }
        return list;
    }

    @Override
    public AwardPerson getByUserId(Long userId, String marketId) {
        return getOne(new LambdaQueryWrapper<AwardPerson>()
                .eq(AwardPerson::getUserId, userId)
                .eq(AwardPerson::getActivityId, marketId));
    }

    @Override
    public void updateChoujTimes(AwardPerson visitUser) {
        update(new LambdaUpdateWrapper<AwardPerson>()
                .eq(AwardPerson::getUserId, visitUser.getUserId())
                .eq(AwardPerson::getActivityId, visitUser.getActivityId())
                .set(AwardPerson::getPrizeNum, visitUser.getPrizeNum()));
    }

    @Override
    public void updateZhongjTimes(AwardPerson visitUser) {
        update(new LambdaUpdateWrapper<AwardPerson>()
                .eq(AwardPerson::getUserId, visitUser.getUserId())
                .eq(AwardPerson::getActivityId, visitUser.getActivityId())
                .set(AwardPerson::getDrawNum, visitUser.getDrawNum()));
    }
}

